package cn.kgm.makeGod.action;

import cn.kgm.makeGod.Character;
import cn.kgm.makeGod.Relationship;
import cn.kgm.makeGod.condition.EventResult;
import cn.kgm.makeGod.condition.WorldState;
import lombok.Builder;
import lombok.Data;

import java.util.Random;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-11 15:01
 * @Description: cn.kgm.makeGod.action.CultivateAction
 */
@Data
@Builder
public class CultivateAction implements Action {

    private boolean together;

    public CultivateAction() {
    }

    public CultivateAction(boolean together) {
        this.together = together;
    }

    @Override
    public void execute(Character actor, Character target, WorldState world, EventResult result) {
        if (together) {
            result.addLog(actor.getName() + " 和 " + target.getName() + " 一起修炼，互相印证功法");

            // 双修效果
            int baseGain = 2;
            Random random = new Random();

            // 关系好的有加成
            Relationship rel = actor.getRelationshipTo(target.getId());
            if (rel != null && rel.getValue() > 70) {
                baseGain += 1;
            }

            // 运气影响
            baseGain += random.nextInt(actor.getLuck() <= 20 ? 20 : actor.getLuck() / 20);
            baseGain += random.nextInt(target.getLuck() <= 20 ? 20 : target.getLuck() / 20);

            actor.setLevel(actor.getLevel() + baseGain);
            target.setLevel(target.getLevel() + baseGain);

            result.addLog("两人都获得了 " + baseGain + " 点修为提升");

            // 关系提升
            if (rel != null) {
                rel.setValue(rel.getValue() + 5);
            }

        } else {
            result.addLog(actor.getName() + " 独自修炼，参悟天道");

            int baseGain = 1;
            Random random = new Random();
            baseGain += random.nextInt(actor.getLuck() > 0 ? actor.getLuck() : 1 / 10);

            actor.setLevel(actor.getLevel() + baseGain);
            result.addLog(actor.getName() + " 获得了 " + baseGain + " 点修为提升");
        }
    }
}
